package alarm;

import org.snmp4j.smi.Integer32;

public enum StartupAlarm {
	risingAlarm("Salita"), 
	fallingAlarm("Discesa"), 
	risingOrFallingAlarm("Salita o discesa");
	
	private String description = null;
	
	private StartupAlarm(String description) {
		this.description = description;
	}
	
	public int getValue() {
		switch (this) {
		case risingAlarm: default: return 1;
		case fallingAlarm: return 2;
		case risingOrFallingAlarm: return 3;
		}
	}
	
	@Override
	public String toString() {
		return description;
	}
	
	public static StartupAlarm fromString(final String value) {
		if(value.equals(risingAlarm.toString()))
			return risingAlarm;
		else if(value.equals(fallingAlarm.toString()))
			return fallingAlarm;
		else if(value.equals(risingOrFallingAlarm.toString()))
			return risingOrFallingAlarm;
		else
			return risingAlarm;
	}

	public Integer32 toVariable() {
		return new Integer32(getValue());
	}
	
	public static StartupAlarm fromVariable(Integer32 variable) {
		switch (variable.getValue()) {
		case 1: default: return risingAlarm;
		case 2: return fallingAlarm;
		case 3: return risingOrFallingAlarm;
		}
	}
}